Component({
  properties: {
    // 当前路由信息
    routeInfo: {
      type: Object,
      value: {}
    }
  },

  data: {
    navTitle: '首页',
    showBackButton: false,
    showMenuButton: false,
    showSearchIcon: false
  },

  observers: {
    'routeInfo': function(route) {
      this.updateNavBar(route)
    }
  },

  methods: {
    updateNavBar(route) {
      if (!route) {
        this.setData({
          navTitle: '首页'
        })
        return
      }
      
      // 计算导航栏标题
      let title = '首页'
      const meta = route.meta || {}
      if (meta.title) {
        title = meta.title
      }
      
      // 判断是否显示返回按钮
      const level = (route.meta && route.meta.level) || 1
      const showBackButton = level > 1

      // 判断是否显示菜单按钮
      const routeName = route.name
      const showMenuButton = false // 临时禁用

      // 判断是否显示搜索图标
      const showSearchIcon = false // 临时禁用

      this.setData({
        navTitle: title,
        showBackButton,
        showMenuButton,
        showSearchIcon
      })
    },

    handleLeftClick() {
      if (this.data.showBackButton) {
        // 返回上一页
        wx.navigateBack()
      }
    },

    handleRightClick() {
      if (this.data.showMenuButton) {
        console.log('显示菜单')
      }
    },

    handleSearchClick() {
      wx.navigateTo({
        url: '/pages/search/search'
      })
    }
  }
})
